#!/bin/bash
#
#**********************************************************************************************
#Author:        Raymond
#QQ:            88563128
#Date:          2022-05-31
#FileName:      mem_monitor.sh
#URL:           raymond.blog.csdn.net
#Description:   The test script
#Copyright (C): 2022 All rights reserved
#*********************************************************************************************
total_memory=$(free |awk '/Mem/{print $2}')
used_memory=$(free |awk '/Mem/{print $3}')

job_name="custom_memory_monitor"
NET_NAME=`ip addr |awk -F"[: ]" '/^2: e.*/{print $3}'`
instance_name=`ip addr show ${NET_NAME}| awk -F" +|/" '/global/{print $3}'`
pushgateway_server="http://172.31.2.102:9091/metrics/job"

cat <<EOF | curl --data-binary @- ${pushgateway_server}/${job_name}/instance/${instance_name}
#TYPE custom_memory_usage gauge
custom_memory_usage ${total_memory}
# TYPE custom_memory_total gauge
custom_memory_total ${used_memory}
EOF
